package com.knife.interfaces.controller.v1;

import com.knife.common.utils.Results;
import com.knife.interfaces.entity.KnifeInterfaceLogRecord;
import com.knife.interfaces.mapper.KnifeInterfaceLogRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： 76875
 * @date： 2022/3/29 星期二 18:11
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@RestController
@RequestMapping("/v1/{organizationId}/log/interface")
public class KnifeInterfaceLogController {

    @Autowired
    private KnifeInterfaceLogRecordMapper knifeInterfaceLogRecordMapper;

    @GetMapping
    public ResponseEntity<Page<KnifeInterfaceLogRecord>> selectPage(@PathVariable Long organizationId,
                                                                    KnifeInterfaceLogRecord knifeInterfaceLogRecord,
                                                                    @RequestParam(defaultValue = "0") int page,
                                                                    @RequestParam(defaultValue = "10") int pageSize) {
        Example<KnifeInterfaceLogRecord> example = Example.of(knifeInterfaceLogRecord);
        return Results.success(knifeInterfaceLogRecordMapper.findAll(example, PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, "creationDate"))));
    }
}
